package net.lzzy.practices.web.models;

import lombok.Getter;
import lombok.Setter;
import net.lzzy.practices.entities.User;
import net.lzzy.practices.utils.JwtUtil;

import java.util.UUID;
@Getter
@Setter
public class VmUser {
    private UUID id;
    private String nickName;
    private String userName;
    private String phone;
    private String email;
    private String avatar;
    private String token;
    private int type;

    private VmUser(){

    }
    private VmUser(User user){
   id = user.getId();
   nickName = user.getNickName();
   userName = user.getUserName();
   phone = user.getPhone();
   email = user.getEmail();
   avatar = user.getAvatar();
   token = UUID.randomUUID().toString();
   type = user.getType();
    }
public static VmUser apiLogin(User user){
        VmUser vm=new VmUser(user);
        vm.setToken(JwtUtil.createToken(user.getId()+""));
        return vm;
}

public static VmUser create(User user,boolean admin){
        VmUser vm=new VmUser(user);
        if(!admin){
            vm.setUserName("****");
            vm.setType(User.TYPE_STUDENT);
        }
        return vm;
}
}
